from typing import Optional, Union

from wazuh.core.engine import get_engine_client
from wazuh.core.engine.models.base import ErrorResponse
from wazuh.core.engine.models.vulnerability import ScanRequest, ScanResponse


async def request_vulnerability_scan(scan_request: ScanRequest) -> Optional[Union[ScanResponse, ErrorResponse]]:
    """Send a vulnerability scan request to the engine.

    Parameters
    ----------
    scan_request : ScanRequest
        Vulnerability scan request.
        
    Returns
    -------
    Optional[Union[ScanResponse, ErrorResponse]]
        Vulnerability scan result, error or None if the response was empty.
    """
    async with get_engine_client() as engine_client:
        return await engine_client.vulnerability.send_scan_request(scan_request)
